<template>

	<view class="bg-box">
    <view class="jsxt l_f_r_c_c">结算系统</view>

	</view>
	<view class="container" style="margin-top:0 ;height: auto;background-color: none;">

		<view class="content" style="padding-top: 0;">

			<view class="head">
				<text></text>
			</view>
			<view class="box">
				<!-- 	<view class="titlebox">
					<view class="left active">
						用户登录
					</view>
					<view class="right" @click="$goURl('/pages/login/register')">
						用户注册
					</view>
				</view> -->
				<view class="list" style="padding-top: 0;">

					<view class="item">
						<view class="items">
							<view class="image">
								账号
							</view>
							<input class="uni-input" maxlength="11" v-model="form.mobile" placeholder="请输入账号" />
						</view>
					</view>

					<view class="item">
						<view class="items">
							<view class="image">
								密码
							</view>
							<input class="uni-input" maxlength="11" v-model="form.password" :password="showPasswords"
								placeholder="请输入密码" />

						</view>
						<uni-icons color="#333" :type="!showPasswords?'eye-filled':'eye-slash-filled'" size="26"
							@click="changePasswords"></uni-icons>
					</view>

					<!-- 	<view class="item">
						<uni-icons :type="!showPassword?'eye-filled':'eye-slash-filled'" size="20"
							></uni-icons>
							<view class="" style="font-size: 10px;"  >
								忘记密码
							</view>
					</view> -->
					<view class="titleboxs">
						<view class="left" @click="$goURl('/pages/login/forget')">
							<view @click="changePassword"></view>
							切换为验证码登录
						</view>
						<view class="right" @click="$goURl('/pages/login/forgets')">
							忘记密码？
						</view>
					</view>
					<!-- <view class="btnBox" @click="login" :style="{background:checked?'':'#0bc4e3'}">
						登录
					</view>
					<view class=" btnBox zcbtnBox" @click="$goURl('/pages/login/register')"
						:style="{background:checked?'':'#FFFFFF'}">
						<text>注册账号</text>
					</view> -->


				</view>

			</view>
				<view class="" >
					<label class="radio" @click="checkedchange"
						style="display: flex;align-items: center;margin-left: 30rpx;margin-top: 150rpx;">
						<uni-icons type="checkbox" color="#F63B29" v-if="checked" size="20"></uni-icons>
						<uni-icons type="circle" v-else size="20"></uni-icons>
						我已阅读并同意<text style="color: #F67800;"
							@click="$goURl('/pages/personal/agreement/agreement?code=1')">《用户协议》</text><text
							style="color: #666;" >与</text><text
							@click="$goURl('/pages/personal/agreement/agreement?code=0')" style="color: #F67800;">《隐私政策》</text>
					</label>
				</view>
			<view class="btnBoxs" @click="login">
				登录
			</view>

		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		getCurrentInstance
	} from "vue";
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app";
	uni.setNavigationBarTitle({
		title: '福宝e·life'
	})


	const openBah = () => {
		window.open('https://beian.miit.gov.cn/')
	}
	const {
		appContext
	} = getCurrentInstance();

	let showPasswords = ref(true)
	let form = reactive({
		mobile: '',
		password: ''
	})
	let checked = ref(false)
	let showPassword = ref(true)
	let agreement = ref(0)
	onShow(() => {
		agreement.value = uni.getStorageSync('agreement')
	})

	function checkedchange() {
		checked.value = !checked.value
	}

	function login() {
		if (!checked.value) {
			uni.showToast({
				icon: 'none',
				position: 'bottom',
				title: '请同意用户协议与隐私协议'
			});
			return false;
		}
		if (!(/^1[3456789]\d{9}$/).test(form.mobile)) {
			uni.showToast({
				icon: 'none',
				position: 'bottom',
				title: '手机号不正确'
			});
			return false;
		}
		if (form.password.length < 6) {
			uni.showToast({
				icon: 'none',
				title: "请输入6位数及以上密码"
			})
			return false
		}
		appContext.config.globalProperties.$request({
			url: `api/login/`,
			method: 'post',
			data: form,
			success(res) {
				if (res.errno == 0) {
					let user = res.data
					user['password'] = form.password
					uni.setStorageSync('userInfo', user)
					let list = uni.getStorageSync('userList') ? uni.getStorageSync('userList') : []
					list = list.filter(item => {
						return item.ID != res.data.ID
					})
					list.unshift(user)
					uni.setStorageSync('userList', list)
					getExplain() //获取首页数据
					uni.showToast({
						icon: 'none',
						title: '登录成功'
					})
					setTimeout(() => {
						// let str = uni.getStorageSync('paymenturl')
						let str = uni.getStorageSync('str')
						if (str) {
							console.log(str, "str22")
							// uni.removeStorageSync('paymenturl')
							uni.removeStorageSync('str')
							uni.reLaunch({
								url: str
							})
						} else {
							uni.navigateTo({
								url: '/pages/personal/index'
							})
						}

					}, 500)
				} else {
					uni.showToast({
						icon: 'none',
						title: res.errmsg
					})
				}
			}
		})
	}

	function getExplain() {
		appContext.config.globalProperties.$request({
			url: `api/decoration/`,
			method: 'get',
			success(res) {
				if (res.errno == 0) {
					uni.setStorageSync('explain', res.data.explain)
					const explain = JSON.parse(res.data.explain)
				} else {
					uni.showToast({
						icon: 'none',
						title: res.errmsg
					})
				}
			}
		})
	}

	function changePassword() {
		showPassword.value = !showPassword.value;
	}

	function changePasswords() {
		console.log('showPassword', showPassword.value)
		showPasswords.value = !showPasswords.value;
	}

	function goDownload() {
    window.open("http://download.guanxikeji.com/download/fubao/",) // 跳安卓端下载地址

    return
		var u = navigator.userAgent,
			app = navigator.appVersion;
		var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
		var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
		// 是安卓浏览器
		if (isAndroid) {
			window.location.href ="http://download.guanxikeji.com/download/fubao/"; // 跳安卓端下载地址

			// 是iOS浏览器
			if (isIOS) {
				window.location.href = 'https://www.fedhema.cn/h5/'; // 跳AppStore下载地址
			}

			// 是微信内部webView
			if (this.is_weixn()) {
				alert("请点击右上角按钮, 点击使用浏览器打开,注意苹果用户请使用苹果自带的Safari 浏览器打开");
			}

			// 是PC端
			//if (IsPC()) {
			//   window.location.href = 'http://192.168.0.101:8000/'; // 公司主页
			//}
		}
	}

	function is_weixn() {
		var ua = navigator.userAgent.toLowerCase();
		if (ua.match(/MicroMessenger/i) == "micromessenger") {
			return true;
		} else {
			return false;
		}
	}

	function IsPC() {
		var userAgentInfo = navigator.userAgent;
		var Agents = ["Android", "iPhone",
			"SymbianOS", "Windows Phone",
			"iPad", "iPod"
		];
		var flag = true;
		for (var v = 0; v < Agents.length; v++) {
			if (userAgentInfo.indexOf(Agents[v]) > 0) {
				flag = false;
				break;
			}
		}
		return flag;
	}
</script>
<style lang="scss" scoped>
	@import '@/static/css/login.scss';
	page{
		background: linear-gradient( 180deg, #FFFFFF 0%, #F4EBDB 100%);
		height: 100vh;
	}
	.gs_c {
		margin-top: 40rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.text {
			color: blueviolet;
		}

	}
	.bg-box{
		height: 528rpx;
		width: 100%;
		background-image: url('https://pili-vod.guanxikeji.com/fubao/img/1755841817057.png');
		background-size: 100%;
	}
</style>
